package com.nfIt.Dbutils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * ClossName:c3p0Dbutil
 * Pakage:com.nfIt.Dbutils
 * Description
 *
 * @Author L
 * @Create 2024/3/12 9:38
 * @Version 2023.1.3
 */
public class c3p0Dbutil {
    /**
     * 定义C3P0数据源对象 - 使用默认配置创建ComboPooledDataSource对象
     */
    private static ComboPooledDataSource cpds = new ComboPooledDataSource();

    // 使用某配置创建ComboPooledDataSource对象
    // private static ComboPooledDataSource cpds = new ComboPooledDataSource("other");

    public static DataSource getDataSource() {
        return cpds;
    }

    /**
     * 获取连接对象
     * @return
     */
    public static Connection getConnection() {
        try {
            return cpds.getConnection();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }

    public static void main(String[] args) {

        System.out.println(c3p0Dbutil.getConnection());
    }
}
